package com.hqw.mindanews.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hqw.mindanews.R;
import com.hqw.mindanews.R.id;
import com.hqw.mindanews.R.layout;
import com.hqw.mindanews.bean.Comments;

public class CommentAdapter extends BaseAdapter {
	private List<Comments> mCommentList;
	private LayoutInflater mInflater;
	private Context mContext;
	public  CommentAdapter(Context context,List<Comments> list) {
		this.mCommentList = list;
		mContext = context;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCommentList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mCommentList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CommentViewHolder commentViewHolder =null;
		if (convertView==null) {
			commentViewHolder = new CommentViewHolder();
			convertView = mInflater.inflate(R.layout.common_item_list,null);
			commentViewHolder.comment = (TextView) convertView.findViewById(R.id.user_comment_detail);
			commentViewHolder.commentTime = (TextView) convertView.findViewById(R.id.comment_time);
			commentViewHolder.userIcon = (ImageView) convertView.findViewById(R.id.comment_user_icon);
			commentViewHolder.userName = (TextView) convertView.findViewById(R.id.comment_user_name);
			commentViewHolder.sayGood = (TextView) convertView.findViewById(R.id.say_good);
			convertView.setTag(commentViewHolder);
		}else {
			commentViewHolder=(CommentViewHolder) convertView.getTag();
		}
		mCommentList.get(position).getUser().getBmobFile().loadImage(mContext, commentViewHolder.userIcon);
		commentViewHolder.comment.setText(mCommentList.get(position).getComment());
		commentViewHolder.userName.setText(mCommentList.get(position).getUser().getUsername());
		commentViewHolder.commentTime.setText(mCommentList.get(position).getCommentTime());
		return convertView;
	}
	
	class CommentViewHolder{
		public ImageView userIcon;
		public TextView userName;
		public TextView commentTime;
		public TextView comment;
		public TextView sayGood;
	}

}
